<?php
/**
 * Created by PhpStorm.
 * User: 低调
 * Date: 2018/5/24
 * Time: 0:09
 */
// 删除文章 kind=1  禁用文章kind=2    删除普通用户kind=3    禁用普通用户 kind=4
// 删除管理员用户kind=5   禁用管理员kind=6      禁用文章显示 kind=7   审核管理员 kind=8
//审核普通用户 kind=9
include("../connectdb.php");
session_start();
$adminId = $_SESSION['id'];     //由adminId查询admin的status==2才有删除权限
$id = $_GET['id'];
$kind = $_GET['kind'];
if($kind==1 and $id>0 and $adminId==1){
    //删除文章，超级管理员才有删除权限
    $sql = "DELETE FROM Article WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('删除成功');location.href='articleList.php';</script>";
    else
        echo "<script>alert('失败');location.href='articleList.php'</script>";
}
elseif($kind==2 and $id>0){
    //禁用文章，所有管理员
    $sql = "UPDATE Article SET status=0 WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('已禁用');location.href='articleList.php';</script>";
    else
        echo "<script>alert('失败');location.href='articleList.php';</script>";
}
elseif($kind==3 and $id>0 and $adminId==1){
    $sql = "DELETE FROM normalUser WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('删除成功');location.href='normalUserList.php';</script>";
    else
        echo "<script>alert('删除失败');location.href='normalUserList.php';</script>";
}
elseif($kind==4 and $id>0){
    //禁用普通用户
    $sql = "UPDATE normalUser SET status=0 WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('已禁用');location.href='normalUserList.php';</script>";
    else
        echo "<script>alert('失败');location.href='normalUserList.php';</script>";
}
elseif($kind==5 and $id>0 and $adminId==1){
    //删除管理员用户 超级管理员权限
    $sql = "DELETE FROM Admin WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('删除成功');location.href='adminList.php';</script>";
    else
        echo "<script>alert('失败');location.href='adminList.php';</script>";
}
elseif($kind==6 and $id>1){
    //禁用管理员
    $sql = "UPDATE Admin SET status=0 WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('已禁用');location.href='adminList.php';</script>";
    else
        echo "<script>alert('失败');location.href='adminList.php';</script>";
}
elseif($kind==7 and $id>0){
    //禁用文章显示
    $sql = "UPDATE Article SET status=1 WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('已显示');location.href='articleList.php';</script>";
    else
        echo "<script>alert('已禁用');location.href='articleList.php';</script>";
}
elseif($kind==8 and $id>0){
    //管理员审核
    $sql = "UPDATE Admin SET status=1 WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('已审核');location.href='adminList.php';</script>";
    else
        echo "<script>alert('失败');location.href='adminList.php';</script>";
}
elseif($kind==9 and $id>0){
    //普通用户审核
    $sql = "UPDATE normalUser SET status=1 WHERE id='$id'";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('已审核');location.href='normalUserList.php';</script>";
    else
        echo "<script>alert('失败');location.href='normalUserList.php';</script>";
}
else
    echo "<script>alert('权限不够，无法操作');location.href='index.php';</script>";

